#include <stdio.h>
#include <string.h>
int sixteen(char a[]) {
    int len = strlen(a);
    int base = 1;
    int j = 0;
	int i ;
    for (i = len - 1; i >= 0; i--) 
	{
        if (a[i] >= '0' && a[i] <= '9') 
		{
            j += (a[i] - '0') * base;
        } 
		else if (a[i] >= 'A' && a[i] <= 'F')
		{
            j += (a[i] - 'A' + 10) * base;
        }
        else if (a[i] >= 'a' && a[i] <= 'f')
		{
            j += (a[i] - 'a' + 10) * base;
        }
        else
        continue ;
        base *= 16;
    }

    return j;
}
int main()
{
	char a[128];
	gets(a);
	int b;
	b=sixteen(a);
	printf("%d",b);
	return 0;
}
